package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzSettingsDraws;
import com.jy.adscm.operation.mscyb.bean.JqzzSettingDraw;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqzzSettingDrawMapper;
import com.jy.adscm.operation.mscyb.service.JqzzSettingDrawService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingList;
import com.jy.adscm.zltx.bean.JyDrawingRole;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingListMapper;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingRoleMapper;
import com.jy.adscm.zltx.service.JyDrawingListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-21
 */
@Service
public class JqzzSettingDrawServiceImpl extends ServiceImpl<JqzzSettingDrawMapper, JqzzSettingDraw> implements JqzzSettingDrawService {
    @Autowired
    JyDrawingListService jyDrawingListService;
    @Autowired
    JyDrawingRoleMapper jyDrawingRoleMapper;
    @Autowired
    JyDrawingListMapper jyDrawingListMapper;
    @Override
    public List<JqzzSettingDraw> selectJqzzSettingDrawsByPid(String pid) {
        List<JyDrawingList> jyDrawingLists=new ArrayList<>();
        Wrapper<JqzzSettingDraw> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",pid);
        List<JqzzSettingDraw> jqbzSettingsDraws = super.selectList(wrapper);
        for (JqzzSettingDraw jqzzSettingDraw : jqbzSettingsDraws) {
            JyDrawingList jyDrawingList = jyDrawingListMapper.selectById(jqzzSettingDraw.getCid());
            if (AdscmBaseUtils.getInstance().isNotEmpty(jyDrawingList,null)){
                jqzzSettingDraw.setCidName(jyDrawingList.getDrawingName());
            }
        }
        return jqbzSettingsDraws;
    }

    @Override
    public List<JyDrawingList> selectAll(Integer parentId,Integer id)throws AdscmSystemException {
        Wrapper<JyDrawingList> wrapper=new EntityWrapper<>();
        wrapper.eq("parent_id",parentId);
        wrapper.eq("drawing_type",id);
        List<JyDrawingList> jyDrawingLists = jyDrawingListMapper.selectList(wrapper);
        return jyDrawingLists;
    }
}
